//
//  commentViewController.m
//  IGOtest
//
//  Created by administrator on 14-2-24.
//  Copyright (c) 2014年 administrator. All rights reserved.
//

#import "commentViewController.h"
#import "AppDelegate.h"

@interface commentViewController ()<NSURLConnectionDataDelegate>
{
    AppDelegate *del;
}

@end

@implementation commentViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    del=[[UIApplication sharedApplication]delegate ];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)return:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)tijiaocomment:(UIButton *)sender {
    if (_commenttxt.text == nil) {
        UIAlertView *alter = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您未输入任何内容" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil ];
        [alter show];
        
    }
    else
    {
        UIAlertView *alters = [[UIAlertView alloc]initWithTitle:@"提示" message:@"感谢你的评论" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil ];
        [alters show];
        NSURL *url =[NSURL URLWithString:@"10.207.1.23:8888/MAMP/addgoodscomment.php"];
        NSMutableURLRequest *request =[[NSMutableURLRequest alloc] initWithURL:url];
        [request setHTTPMethod:@"POST"];
        NSString *bodystring =[NSString stringWithFormat:@"goodsid=%@&uesrid=%@&username=%@&goodscommen=%@",nil,nil,nil,_goods.igoodscomment];
        NSData *body = [bodystring dataUsingEncoding:NSUTF8StringEncoding];
        [request setHTTPBody:body];
        NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self ];
        [conn start];
    }
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    if([str isEqualToString:@"insert success!"])
    {
        NSLog(@"成功！");
        
    }
    else{
        NSLog(@"失败！");
    }
    
}

@end
